import numpy as np


def handle_binary_image(image_array, top, bottom, left, right):
    width = image_array.shape[1]; height = image_array.shape[0]
    if len(top) != width: top = image_array[0, :]
    if len(bottom) != width: bottom = image_array[-1, :]
    if len(left) != height: left = image_array[:, 0]
    if len(right) != height: right = image_array[:, -1]

    left_image_array_0 = image_array[:, 1:]
    right_ = right.reshape(-1, 1)
    left_image_array = np.hstack((left_image_array_0, right_))

    right_image_array_0 = image_array[:, :-1]
    left_ = left.reshape(-1, 1)
    right_image_array = np.hstack((left_, right_image_array_0))

    top_image_array_0 = image_array[1:, :]
    bottom_ = bottom.reshape(1, -1)
    top_image_array = np.append(top_image_array_0, bottom_, axis=0)

    bottom_image_array_0 = image_array[:-1, :]
    top_ = top.reshape(1, -1)
    bottom_image_array = np.append(top_, bottom_image_array_0, axis=0)

    image_indices = np.where((image_array == 1) &
                             ((left_image_array == 0) | (right_image_array == 0) |
                              (top_image_array == 0) | (bottom_image_array == 0)))

    t = 12